import { PageParam } from '@/services/common'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface SettingVO {
    /**
     * id
     */
    id: string
    /**
     * 客资通知
     */
    customerNotify: string
    /**
     * 订单通知
     */
    orderNotify: string
    orderNotifyText: string
    customerNotifyText: string
}

export interface SettingQueryDTO extends PageParam {
    /**
     * id
     */
    id?: string
    /**
     * 客资通知
     */
    customerNotify: string
    /**
     * 订单通知
     */
    orderNotify: string
}

export interface SettingUpdateDTO {
    /**
     * id
     */
    id?: string
    /**
     * 客资通知
     */
    customerNotify?: string
    /**
     * 订单通知
     */
    orderNotify?: string

    orderNotifyText: string
    customerNotifyText: string
}

export const getSettingById = async (id: string) => {
    return request<SettingVO>(`/api/setting?id=${id}`, { method: 'GET' })
}

export const getSettingList = async (params: SettingQueryDTO) => {
    return request<Array<SettingVO>>(`/api/setting/list`, { method: 'GET', params })
}

export const getSettingPage = async (params: SettingQueryDTO) => {
    let response = await request<Array<SettingVO>>(`/api/setting/page`, { method: 'GET', params })
    return covertTableData(response)
}

export const updateSetting = async (settingUpdateDTO: SettingUpdateDTO) => {
    return request<SettingVO>(`/api/setting/update`, { method: 'POST', data: settingUpdateDTO })
}

export const saveSetting = async (settingUpdateDTO: SettingUpdateDTO) => {
    return request<SettingVO>(`/api/setting/save`, { method: 'POST', data: settingUpdateDTO })
}

export const removeSetting = async (id: string) => {
    return request<boolean>(`/api/setting/remove?id=${id}`, { method: 'POST' })
}

export const getMarketSetting = async () => {
    return request<SettingVO>(`/api/setting/marketingSetting`, { method: 'POST' })
}
